package com.xjtu.mybatisplus.service.impl;

import com.xjtu.mybatisplus.common.utls.BaseContext;
import com.xjtu.mybatisplus.model.domain.Mailbox;
import com.xjtu.mybatisplus.mapper.MailboxMapper;
import com.xjtu.mybatisplus.model.dto.MailDTO;
import com.xjtu.mybatisplus.service.MailboxService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lsong
 * @since 2023-12-27
 */
@Service
public class MailboxServiceImpl extends ServiceImpl<MailboxMapper, Mailbox> implements MailboxService {

    @Autowired(required = false)
    private MailboxMapper mailboxMapper;
    @Override
    public void addMail(String content) {
        Mailbox mailbox=new Mailbox();
        mailbox.setUserId(BaseContext.getCurrentId());
        mailbox.setContent(content);
        mailboxMapper.insert(mailbox);
    }

    @Override
    public void replyMail(MailDTO mailDTO) {
        Mailbox mailbox=mailboxMapper.selectById(mailDTO.getId());
        mailbox.setReply(mailDTO.getReply());
        mailbox.setStatus(1);
        mailbox.setUpdateTime(null);
        mailboxMapper.updateById(mailbox);
    }

    @Override
    public void setPublic(MailDTO mailDTO) {
        Mailbox mailbox=mailboxMapper.selectById(mailDTO.getId());
        mailbox.setIsPublic(mailDTO.getIsPublic());
        mailbox.setUpdateTime(null);
        mailboxMapper.updateById(mailbox);
    }
}
